home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / doc / SetResult.3 < prev    next >
Text File  |  1993-02-14  |  6KB  |  162 lines

  1. '\"
  2. '\" Copyright 1989 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. .so man.macros
  11. .HS Tcl_SetResult tcl
  12. .BS
  13. .SH NAME
  14. Tcl_SetResult, Tcl_AppendResult, Tcl_AppendElement, Tcl_ResetResult \- manipulate Tcl result string
  15. .SH SYNOPSIS
  16. .nf
  17. \fB#include <tcl.h>\fR
  18. .sp
  19. .VS
  20. \fBTcl_SetResult\fR(\fIinterp, string, freeProc\fR)
  21. .VE
  22. .sp
  23. \fBTcl_AppendResult(\fIinterp, string, string, ... , \fB(char *) NULL\fR)
  24. .sp
  25. .VS
  26. \fBTcl_AppendElement\fR(\fIinterp, string, noSep\fR)
  27. .sp
  28. \fBTcl_ResetResult\fR(\fIinterp\fR)
  29. .sp
  30. \fBTcl_FreeResult\fR(\fIinterp\fR)
  31. .VE
  32. .SH ARGUMENTS
  33. .AS Tcl_FreeProc freeProc
  34. .AP Tcl_Interp *interp out
  35. Interpreter whose result is to be modified.
  36. .AP char *string in
  37. String value to become result for \fIinterp\fR or to be
  38. appended to existing result.
  39. .AP Tcl_FreeProc freeProc in
  40. .VS
  41. Address of procedure to call to release storage at
  42. \fIstring\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or
  43. \fBTCL_VOLATILE\fR.
  44. .AP int noSep in
  45. If non-zero then don't output a space character before this element,
  46. even if the element isn't the first thing in the result string.
  47. .VE
  48. .BE
  49.  
  50. .SH DESCRIPTION
  51. .PP
  52. The procedures described here are utilities for setting the
  53. result/error string in a Tcl interpreter.
  54. .PP
  55. \fBTcl_SetResult\fR
  56. arranges for \fIstring\fR to be the return string for the current Tcl
  57. command in \fIinterp\fR, replacing any existing result.
  58. .VS
  59. If \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIstring\fR
  60. refers to an area of static storage that is guaranteed not to be
  61. modified until at least the next call to \fBTcl_Eval\fR.
  62. If \fIfreeProc\fR
  63. is \fBTCL_DYNAMIC\fR it means that \fIstring\fR was allocated with a call
  64. to \fBmalloc()\fR and is now the property of the Tcl system.
  65. \fBTcl_SetResult\fR will arrange for the string's storage to be
  66. released by calling \fBfree()\fR when it is no longer needed.
  67. If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIstring\fR
  68. points to an area of memory that is likely to be overwritten when
  69. \fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame).
  70. In this case \fBTcl_SetResult\fR will make a copy of the string in
  71. dynamically allocated storage and arrange for the copy to be the
  72. return string for the current Tcl command.
  73. .PP
  74. If \fIfreeProc\fR isn't one of the values \fBTCL_STATIC\fR,
  75. \fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the address
  76. of a procedure that Tcl should call to free the string.
  77. This allows applications to use non-standard storage allocators.
  78. When Tcl no longer needs the storage for the string, it will
  79. call \fIfreeProc\fR.  \fIFreeProc\fR should have arguments and
  80. result that match the type \fBTcl_FreeProc\fR:
  81. .nf
  82. .RS
  83.  
  84. typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
  85.  
  86. .RE
  87. .fi
  88. When \fIfreeProc\fR is called, its \fIblockPtr\fR will be set to
  89. the value of \fIstring\fR passed to \fBTcl_SetResult\fR.
  90. .VE
  91. .PP
  92. If \fIstring\fR is \fBNULL\fR, then \fIfreeProc\fR is ignored
  93. and \fBTcl_SetResult\fR
  94. re-initializes \fIinterp\fR's result to point to the pre-allocated result
  95. area, with an empty string in the result area.
  96. .PP
  97. .VS
  98. If \fBTcl_SetResult\fR is called at a time when \fIinterp\fR holds a
  99. result, \fBTcl_SetResult\fR does whatever is necessary to dispose
  100. of the old result (see the \fBTcl_Interp\fR manual entry for details
  101. on this).
  102. .VE
  103. .PP
  104. \fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces.
  105. It takes each of its \fIstring\fR arguments and appends them in order
  106. to the current result associated with \fIinterp\fR.
  107. .VS
  108. If the result is in its initialized empty state (e.g. a command procedure
  109. was just invoked or \fBTcl_ResetResult\fR was just called),
  110. then \fBTcl_AppendResult\fR sets the result to the concatenation of
  111. its \fIstring\fR arguments.
  112. .VE
  113. \fBTcl_AppendResult\fR may be called repeatedly as additional pieces
  114. of the result are produced.
  115. \fBTcl_AppendResult\fR takes care of all the
  116. storage management issues associated with managing \fIinterp\fR's
  117. result, such as allocating a larger result area if necessary.
  118. Any number of \fIstring\fR arguments may be passed in a single
  119. call;  the last argument in the list must be a NULL pointer.
  120. .PP
  121. \fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR in
  122. .VS
  123. that it allows results to be built up in pieces.
  124. However, \fBTcl_AppendElement\fR takes only a single \fIstring\fR
  125. argument and it appends that argument to the current result
  126. as a proper Tcl list element.
  127. \fBTcl_AppendElement\fR adds backslashes or braces if necessary
  128. to ensure that \fIinterp\fR's result can be parsed as a list and that
  129. \fIstring\fR will be extracted as a single element.
  130. Under normal conditions, \fBTcl_AppendElement\fR will add a space
  131. character to \fIinterp\fR's result just before adding the new
  132. list element, so that the list elements in the result are properly
  133. separated.
  134. However, if \fIinterp\fR's result is empty when \fBTcl_AppendElement\fR
  135. is called, or if the \fInoSep\fR argument is 1, then no space
  136. is added.
  137. .PP
  138. \fBTcl_ResetResult\fR clears the result for \fIinterp\fR,
  139. freeing the memory associated with it if the current result was
  140. dynamically allocated.
  141. It leaves the result in its normal initialized state with
  142. \fIinterp->result\fR pointing to a static buffer containing
  143. \fBTCL_RESULT_SIZE\fR characters, of which the first character
  144. is zero.
  145. \fBTcl_ResetResult\fR also clears the error state managed by
  146. \fBTcl_AddErrorInfo\fR and \fBTcl_SetErrorCode\fR.
  147. .PP
  148. \fBTcl_FreeResult\fR is a macro that performs part of the work
  149. of \fBTcl_ResetResult\fR.
  150. It frees up the memory associated with \fIinterp\fR's result
  151. and sets \fIinterp->freeProc\fR to zero, but it doesn't
  152. change \fIinterp->result\fR or clear error state.
  153. \fBTcl_FreeResult\fR is most commonly used when a procedure
  154. is about to replace one result value with another.
  155. .VE
  156.  
  157. .SH "SEE ALSO"
  158. Tcl_AddErrorInfo, Tcl_SetErrorCode, Tcl_Interp
  159.  
  160. .SH KEYWORDS
  161. append, command, element, list, result, return value, interpreter
  162.